--装甲 巨型1号坦克 （ZCG）
function c77240139.initial_effect(c)
    --special summon
    local e1=Effect.CreateEffect(c)
    e1:SetType(EFFECT_TYPE_FIELD)
    e1:SetCode(EFFECT_SPSUMMON_PROC)
    e1:SetProperty(EFFECT_FLAG_UNCOPYABLE)
    e1:SetRange(LOCATION_HAND)
    e1:SetCondition(c77240139.spcon)
    e1:SetOperation(c77240139.spop)
    c:RegisterEffect(e1)

    --
    local e2=Effect.CreateEffect(c)
    e2:SetDescription(aux.Stringid(77240139,0))
    e2:SetCategory(CATEGORY_SPECIAL_SUMMON)
    e2:SetType(EFFECT_TYPE_SINGLE+EFFECT_TYPE_TRIGGER_O)
    e2:SetCode(EVENT_REMOVE)
    e2:SetTarget(c77240139.target)
    e2:SetOperation(c77240139.operation)
    c:RegisterEffect(e2)    
--negate
    local e0=Effect.CreateEffect(c)
    e0:SetCategory(CATEGORY_NEGATE+CATEGORY_DESTROY)
    e0:SetType(EFFECT_TYPE_CONTINUOUS+EFFECT_TYPE_FIELD)
    e0:SetCode(EVENT_CHAINING)
    e0:SetProperty(EFFECT_FLAG_DAMAGE_STEP+EFFECT_FLAG_DAMAGE_CAL)
    e0:SetRange(LOCATION_MZONE)
    e0:SetCondition(c77240139.negcon)
    e0:SetTarget(c77240139.negtg)
    e0:SetOperation(c77240139.negop)
    c:RegisterEffect(e0)
end
function c77240139.negcon(e,tp,eg,ep,ev,re,r,rp)
    local c=e:GetHandler()
    if not re:IsHasProperty(EFFECT_FLAG_CARD_TARGET) then return false end
    local g=Duel.GetChainInfo(ev,CHAININFO_TARGET_CARDS)
    if not g or not g:IsContains(c) then return false end
    return rp==1-tp
end
function c77240139.negtg(e,tp,eg,ep,ev,re,r,rp,chk)
    if chk==0 then return true end
    Duel.SetOperationInfo(0,CATEGORY_NEGATE,eg,1,0,0)
    if re:GetHandler():IsRelateToEffect(re) and re:GetHandler():IsDestructable() then
        Duel.SetOperationInfo(0,CATEGORY_DESTROY,eg,1,0,0)
    end
end
function c77240139.negop(e,tp,eg,ep,ev,re,r,rp)
    if Duel.NegateActivation(ev) and re:GetHandler():IsRelateToEffect(re) then
        Duel.Destroy(re:GetHandler(),REASON_EFFECT)
    end
end
function c77240139.spfilter(c)
    return c:IsAbleToGraveAsCost()
end
function c77240139.spcon(e,c)
    if c==nil then return true end
    local tp=c:GetControler()
    return Duel.GetLocationCount(tp,LOCATION_MZONE)>0
        and Duel.IsExistingMatchingCard(c77240139.spfilter,tp,LOCATION_ONFIELD,0,1,nil)
        and Duel.IsExistingMatchingCard(c77240139.spfilter,tp,0,LOCATION_ONFIELD,1,nil)
end
function c77240139.spop(e,tp,eg,ep,ev,re,r,rp,c)
    Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_TOGRAVE)
    local g=Duel.SelectMatchingCard(tp,c77240139.spfilter,tp,LOCATION_ONFIELD,0,1,1,nil)
    local g1=Duel.SelectMatchingCard(tp,c77240139.spfilter,tp,0,LOCATION_ONFIELD,1,1,nil)
    g:Merge(g1)
    Duel.SendtoGrave(g,REASON_COST)
end
function c77240139.filter(c,e,tp)
    return c:IsSetCard(0xa110) and c:IsCanBeSpecialSummoned(e,0,tp,false,false)
end
function c77240139.target(e,tp,eg,ep,ev,re,r,rp,chk)
    if chk==0 then return Duel.GetLocationCount(tp,LOCATION_MZONE)>2
        and Duel.IsExistingMatchingCard(c77240139.filter,tp,LOCATION_HAND,0,3,nil,e,tp) end
    Duel.SetOperationInfo(0,CATEGORY_SPECIAL_SUMMON,nil,3,tp,LOCATION_HAND)
end
function c77240139.operation(e,tp,eg,ep,ev,re,r,rp)
    if Duel.GetLocationCount(tp,LOCATION_MZONE)<=0 then return end
    Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_SPSUMMON)
    local g=Duel.SelectMatchingCard(tp,c77240139.filter,tp,LOCATION_HAND,0,3,3,nil,e,tp)
    if g:GetCount()>0 then
        Duel.SpecialSummon(g,0,tp,tp,false,false,POS_FACEUP)
    end
end

